const api = require('../../../utils/interface.js')
const math = require('../../../utils/math.js')
const tools = require('../../../utils/util.js')
Page({
  data: {
    details: {},
    cardName: "",
    tabstate:false,
    orderNumberId:"",
    src:""
  },
  gopay() {
    wx.navigateTo({
      url: '/pages/myorder/payma/payma?orderNumberId=' + this.data.orderNumberId
    })
  },
  onLoad: function (options) {
    console.log(options)
    this.getConsumption(options.orderNumber,"11")
    let cardName = wx.getStorageSync('userInfo').name
    if (options.tabIndex=="2"){
      this.setData({
        tabstate:true,
        
      })
    }else{
      this.setData({
        tabstate: false,
        
      })
    }
    this.setData({
      cardName: cardName
    })
  },
  // 获取消费订单明细
  getConsumption(orderNumber) {
    api.getOrder({ orderNumber }).then(res => {
      res.data.result.createTime_ = tools.formatTime(new Date(res.data.result.createTime))
      res.data.result.orderAmount_ = math.divide(res.data.result.orderAmount, 100)
      res.data.result.downAmount = math.divide(res.data.result.downAmount,100)
      res.data.result.couponAmount_ = math.divide(res.data.result.couponAmount, 100)
      res.data.result.orderAmount_ = math.divide(res.data.result.orderAmount, 100)
      res.data.result.rebateAmount = math.divide(Number(res.data.result.rebateAmount), 100)
      res.data.result.payAmount = math.divide(res.data.result.payAmount, 100)
      res.data.result.redPackedAmount = math.divide(res.data.result.redPackedAmount, 100)
      res.data.result.fullReductionAmount = math.divide(res.data.result.fullReductionAmount,100)
      res.data.result.payType_ = ""
      switch (res.data.result.payType) {
        case '1':
          res.data.result.payType_ = '支付宝'
          this.data.src = '/static/zfb.png'
          break;
        case '2':
          res.data.result.payType_ = '微信'
          this.data.src = '/static/wechat.png'
          break;
        case '3':
          res.data.result.payType_ = '银联'
          this.data.src = '/static/yl.png'
          break;
        case '4':
          res.data.result.payType_ = '余额'
          this.data.src = '/static/ye.png'
          break;
        case '5':
          res.data.result.payType_ = '现金'
          this.data.src = '/static/xj.png'
          break;
        case '6':
          res.data.result.payType_ = '一网通'
          break;
      }
      this.setData({
        details: res.data.result,
        orderNumberId: res.data.result.orderNumber,
        src:this.data.src
      })
    })
  },

  onShow: function () {

  },
  // onUnload() {
  //   console.log('返回按钮')
  //   wx.switchTab({
  //     url: '/pages/index/index'
  //   })
  // }
  // onUnload() {
  //   console.log('返回按钮')
  //   wx.navigateBack({
  //     delta: 1
  //   })
  // }

})